package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {


    /*
     * 统计在分类id下的菜品数量
     * */
    @Select("select count(category_id) from dish where category_id=#{id}")
    Integer countByCategoryId(Long id);

    /*
     * 根据菜品名称查询菜品id
     * */
    @Select("select id from dish where name=#{name}")
    Long selsctId(String name);

    /*
     * 新增菜品
     * */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user,status) " +
            "VALUES (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})")
    Long insert(Dish dish);

    /*
     * 菜品分页查询
     * */
    Page<DishVO> selectPage(DishPageQueryDTO dishPageQueryDTO);

    /*
     * 根据id查询菜品并返回dish对象的数据
     * */
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);

    /*
     * 根据ids批量删除菜品
     * */
    void deleteByIds(List<Long> ids);

    /*
     * 根据id查询菜品信息
     * */
    @Select("select * from dish where id=#{id}")
    Dish selsctById(Long id);

    /*
     * 更新菜品信息
     * */
    @AutoFill(value = OperationType.UPDATE)
    void updateDish(Dish dish);

    /*
     * 根据分类查询菜品
     * */
    List<Dish> selsctDishListByCategoryId(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
